/*!
 * \file mutex.cpp
 * \brief contains a generic mutex implementation to inherit from
 * \author Xavier SCHMERBER
 * \version 1
 */

#include "mutex.hh"
#include <iostream>

Mutex::Mutex()
{
    if (pthread_mutex_init(&_lock, NULL) != 0)
        throw logic_error("Mutex creation failed");
}

Mutex::~Mutex()
{
    if (pthread_mutex_destroy(&_lock) != 0)
        throw logic_error("Mutex destruction failed");
}

bool Mutex::lock()
{
    if (pthread_mutex_lock(&_lock))
        return (false);
    return (true);
}

bool Mutex::unlock()
{
    if (pthread_mutex_unlock(&_lock))
        return (false);
    return (true);
}
